import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
var _excluded = ["title", "visible", "onCancel", "onOk", "dataSource", "loading", "defaultSelectedRow", "prompt"];
import React, { PureComponent } from 'react';
import { Modal, Table } from 'antd'; // import { isNumber } from 'lodash';

import { tableScrollWidth } from 'utils/utils';

var Organization = /*#__PURE__*/function (_PureComponent) {
  _inherits(Organization, _PureComponent);

  var _super = _createSuper(Organization);

  function Organization() {
    var _this;

    _classCallCheck(this, Organization);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));
    _this.state = {
      selectedRow: _this.props.defaultSelectedRow
    };
    _this.defaultRowkey = 'id';
    return _this;
  }

  _createClass(Organization, [{
    key: "ok",
    value: function ok() {
      var _this$props = this.props,
          _this$props$onOk = _this$props.onOk,
          onOk = _this$props$onOk === void 0 ? function (e) {
        return e;
      } : _this$props$onOk,
          _this$props$onCancel = _this$props.onCancel,
          onCancel = _this$props$onCancel === void 0 ? function (e) {
        return e;
      } : _this$props$onCancel;
      var selectedRow = this.state.selectedRow;
      this.setState({
        selectedRow: {}
      });
      onOk(selectedRow);
      onCancel();
    }
  }, {
    key: "cancel",
    value: function cancel() {
      var _this$props$onCancel2 = this.props.onCancel,
          onCancel = _this$props$onCancel2 === void 0 ? function (e) {
        return e;
      } : _this$props$onCancel2;
      onCancel();
    }
  }, {
    key: "onRow",
    value: function onRow(record) {
      var _this2 = this;

      var setSelect = function setSelect() {
        _this2.setState({
          selectedRow: record
        });
      };

      return {
        onClick: function onClick() {
          setSelect();
        }
      };
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          title = _this$props2.title,
          visible = _this$props2.visible,
          onCancel = _this$props2.onCancel,
          onOk = _this$props2.onOk,
          dataSource = _this$props2.dataSource,
          loading = _this$props2.loading,
          defaultSelectedRow = _this$props2.defaultSelectedRow,
          _this$props2$prompt = _this$props2.prompt,
          prompt = _this$props2$prompt === void 0 ? {} : _this$props2$prompt,
          others = _objectWithoutProperties(_this$props2, _excluded);

      var _this$state$selectedR = this.state.selectedRow,
          selectedRow = _this$state$selectedR === void 0 ? {} : _this$state$selectedR;
      var tableColumns = [{
        title: prompt.unitCode,
        dataIndex: 'unitCode'
      }, {
        title: prompt.unitName,
        dataIndex: 'unitName'
      }];
      var tableProps = {
        loading: loading,
        dataSource: dataSource,
        pagination: false,
        bordered: true,
        childrenColumnName: 'childHrUnits',
        onRow: this.onRow.bind(this),
        columns: tableColumns,
        scroll: {
          x: tableScrollWidth(tableColumns)
        },
        rowKey: 'unitId',
        rowSelection: {
          type: 'radio',
          selectedRowKeys: [selectedRow.unitId]
        }
      };
      return /*#__PURE__*/React.createElement(Modal, Object.assign({
        title: prompt.selectUnit,
        visible: visible,
        onOk: this.ok.bind(this),
        onCancel: this.cancel.bind(this),
        destroyOnClose: true
      }, others), /*#__PURE__*/React.createElement(Table, tableProps));
    }
  }]);

  return Organization;
}(PureComponent);

export { Organization as default };